<template>
  <a-modal
    :maskClosable="maskClosable"
    title="云平台资源详情"
    :width="600"
    :visible="visible"
    :confirm-loading="confirmLoading"
    :okButtonProps="{ class: { 'jee-hidden': true } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :labelCol="{ span: 6 }" :wrapperCol="{ span: 14 }" :form="form">
        <a-form-item label="资源名称">
          <span class="ant-form-text"> {{ model.name }} </span>
        </a-form-item>

        <a-form-item label="资源类型">
          <span class="ant-form-text"> {{ model.typeName }} </span>
        </a-form-item>

        <a-form-item label="虚拟机ID">
          <span class="ant-form-text"> {{ model.id }} </span>
        </a-form-item>

        <a-form-item label="数据中心">
          <span class="ant-form-text"> {{ model.datacenterName }} </span>
        </a-form-item>

        <!--<a-form-item label="资源所属服务器">
          <span class="ant-form-text"> {{ model.nodeName }} </span>
        </a-form-item>-->
        <template v-if="model.type === 0">
          <a-form-item label="CPU">
            <span class="ant-form-text">{{ model.cpuCores ? (model.cpuCores + ' 核') : '' }}</span>
          </a-form-item>
          <a-form-item label="内存">
            <span class="ant-form-text">{{ model.memory ? (model.memory + ' GB') : '' }}</span>
          </a-form-item>
        </template>
        <a-form-item label="创建时间">
          <span class="ant-form-text"> {{ model.createTime }} </span>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>
<script>
import { gPostAction } from "@/api/manage";
export default {
  name: "DetailModal",
  data() {
    return {
      visible: false,
      confirmLoading: false,
      form: this.$form.createForm(this),
      maskClosable: false,
      model: {},
    };
  },
  methods: {
    loadInfo(id) {
      return new Promise((resolve, reject) => {
        gPostAction('/cloud_resource/detail', { id, title:"精确管控与供电制冷联动-基础资源细粒度感知-资源管理L3层-云平台资源" }).then((res) => {
          if (res.success) {
            this.model = res.data;
            resolve(res)
          } else {
            reject(res)
          }
        })
      })
    },
    detail(record) {
      this.visible = true;
      this.model = {};
      this.loadInfo(record.id);
    },
    handleCancel() {
      this.visible = false;
      this.confirmLoading = false;
    },
  },
};
</script>
